var cache = require('../redis')

module.exports = {
  pres: [
    function (req, res, next) {
      res.setHeader('Access-Control-Allow-Origin', '*')
      if (req.method === 'OPTIONS') {
        res.setHeader('Access-Control-Allow-Headers', 'accept, access-control-allow-origin, content-type, Authorization')
        res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE')
        res.send(200)
        return next(false)
      }
      return next()
      // if (req.url === '/api/token/login' || req.url.indexOf('/api/wechat/message') !== -1 || req.url === '/api/wechat/login') {
      //   return next()
      // }
      // if (!req.headers.authorization) {
      //   res.send({success: false, msg: '未授权'})
      //   return next(false)
      // }
      // cache.tokens.checkToken(req.headers.authorization).then(result => {
      //   if (result.success) {
      //     return next()
      //   } else {
      //     res.send({success: false, msg: 'session已过期'})
      //     return next(false)
      //   }
      // })
    }
  ],
  uses: [
    function (req, res, next) { return next() }
  ],
  report:
  [
    function (req, res, next) { return next() }
  ]
}
